//
//  ZTAlert.m
//  ZHYYView
//
//  Created by MT-SW-005 on 2021/11/11.
//  Copyright © 2021 yuan zhang. All rights reserved.
//

#import "ZTAlert.h"

@implementation ZTAlert



//采用Window的方式展示
+(NSUInteger)ShowAlertWindow
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setMessageText:@"messageText"];
    [alert setInformativeText:@"informativeText"];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert addButtonWithTitle:@"Quit"];
    
    NSUInteger action = [alert runModal];
   
//    响应window的按钮事件
    if(action == 1000)
    {
        NSLog(@"ok");
        return 0;
    }
    else if(action == 1001 )
    {
        NSLog(@"cancel");
        return 1;
    }
    else {
        NSLog(@"quit");
        return -1;
    }
}

//采用Window的方式展示
+(NSUInteger)ShowAlertWindowWithMsg:(NSString*)msg informative:(NSString*)info
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setMessageText:msg];
    [alert setInformativeText:info];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert addButtonWithTitle:@"Quit"];
    
    NSUInteger action = [alert runModal];
   
//    响应window的按钮事件
    if(action == 1000)
    {
        NSLog(@"ok");
        return 0;
    }
    else if(action == 1001 )
    {
        NSLog(@"cancel");
        return 1;
    }
    else {
        NSLog(@"quit");
        return -1;
    }
}


//采用Window的方式展示
+(NSUInteger)ShowAlertWindowWithMsg:(NSString*)msg informative:(NSString*)info view:(NSView*)aView
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setMessageText:msg];
    [alert setInformativeText:info];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert addButtonWithTitle:@"Quit"];
    [alert setAccessoryView:aView];
    NSUInteger action = [alert runModal];
   
//    响应window的按钮事件
    if(action == 1000)
    {
        NSLog(@"ok");
        return 0;
    }
    else if(action == 1001 )
    {
        NSLog(@"cancel");
        return 1;
    }
    else {
        NSLog(@"quit");
        return -1;
    }
}






//采用Sheet的方式展示
+(NSInteger)ShowAlertSheet;
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setMessageText:@"messageText"];
    [alert setInformativeText:@"informativeText"];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert addButtonWithTitle:@"Quit"];
    
    __block NSInteger res =0;
    [alert beginSheetModalForWindow:[NSApplication sharedApplication].keyWindow completionHandler:^(NSModalResponse returnCode) {
        if (returnCode == NSAlertFirstButtonReturn) {
            NSLog(@"ok");
            res = 0;
        } else if (returnCode == NSAlertSecondButtonReturn) {
            NSLog(@"cancel");
            res = 1;
        } else {
            NSLog(@"quit");
            res = -1;
        }
    }];
    return res;
}


//采用Sheet的方式展示
+(NSInteger)ShowAlertSheetWithMsg:(NSString*)msg informative:(NSString*)info;
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setMessageText:msg];
    [alert setInformativeText:info];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert addButtonWithTitle:@"Quit"];
    
    __block NSInteger res =0;
    [alert beginSheetModalForWindow:[NSApplication sharedApplication].keyWindow completionHandler:^(NSModalResponse returnCode) {
        if (returnCode == NSAlertFirstButtonReturn) {
            NSLog(@"ok");
            res = 0;
        } else if (returnCode == NSAlertSecondButtonReturn) {
            NSLog(@"cancel");
            res = 1;
        } else {
            NSLog(@"quit");
            res = -1;
        }
    }];
    return res;
}

@end

